#ifndef LLCC68_H
#define LLCC68_H
#include "stdint.h"
#include "stdio.h"
#include "string.h"
#include "stdarg.h"
#ifdef __cplusplus
extern "C"
{
#endif
/** 
 * @defgroup debug
 * @brief llcc68 debug module
 * @{
 */
#define LC68_DEBUG_ENABLE 0

#if LC68_DEBUG_ENABLE

#define LC68_DEBUG(X, ...)      \
    do                            \
    {                             \
        printf(X, ##__VA_ARGS__); \
    } while (0)

#else

#define LC68_DEBUG(...) \
    do                    \
    {                     \
    } while (0)

#endif
/**
 * @defgroup 断言
 * @brief 
 * @brief LLCC68 ASSERT module
 * */
#define LC68_ASSERT(expr, action) \
            if (!(expr)) { \
                action; \
            }
#define LC68_MAlLOC(size) malloc(size)
#define LC68_FREE(ptr)    free(ptr)

typedef enum {
    LC68_OK = 0,        // success
    LC68_ERR_NULL_PTR,  // null pointer
    LC68_ERR_TIMEOUT,   // timeout
    LC68_ERR_BUSY,      // busy
    LC68_ERR_INT        //interrupt error
} lc68_err_t;

typedef enum{
	T_LC68_PIN_RESET = 0,
	T_LC68_PIN_SET = 1
} lc68_pin_VSTA;  //value status

typedef struct
{
	void *busy_port;  // busy port
	uint16_t busy_pin;
	void *reset_port; // reset port
    uint16_t reset_pin;
    void *irq_port;   // resved port
    uint16_t irq_pin; //resved port
}lc68_gpio_t;

typedef void (*lc68_pincfg_f)(void *port, uint16_t pin);
typedef void (*lc68_delay_f)(uint32_t us);
typedef void (*lc68_write_f)(void *port, uint16_t pin, uint8_t pin_val);
typedef uint8_t (*lc68_read_f)(void *port, uint16_t pin);
typedef uint8_t(*lc68_spi_write_read_f)(uint8_t *in_buf, uint16_t in_len,uint8_t *out_buf, uint16_t out_le);
typedef void (*receive_callback)(uint16_t type,uint8_t *buf, uint16_t len);

typedef struct llcc68_handle_sp
{
    void *arg;                   /**< point to a hardware spi structure */
    lc68_delay_f delay_ms;                /**< point to a delay_ms function address */
    lc68_pincfg_f cfg_out;                /**< point to a cfg_out function address */
    lc68_pincfg_f cfg_in;                 /**< point to a cfg_in function address */
    lc68_pincfg_f cfg_irq;                /**< point to a cfg_irq function address */
    lc68_write_f pwrite;                  /**< point to a port write function address */
    lc68_read_f pread;                    /**< point to a port read function address */
    lc68_spi_write_read_f spi_write_read; /**< point to a spi write read function address */
    receive_callback rev_cb;              /**< point to a receive callback function address */
    const lc68_gpio_t *hw_gpio;                 /**< point to a hardware gpio structure */

} llcc68_handle_t;

void t_lc68_destroy(llcc68_handle_t *ctx);

llcc68_handle_t *t_lc68_create( 
    void *arg,
    lc68_pincfg_f cfgout_func,
    lc68_pincfg_f cfgin_func,
    lc68_delay_f delay_func,
    lc68_write_f i2c_w_func,
    lc68_read_f i2c_r_func,
    lc68_spi_write_read_f spi_write_read_func,
    const lc68_gpio_t *hw_gpio);



















#ifdef __cplusplus
}
#endif


#endif // LLCC68_H
